import UserTaskAssign from "./components/generalFormComponents/userTaskComponents/GeneralComponents/userTaskAssign"
import login from "@/views/login";

// 通用表单
export function commonForm() {
    return {
        models: {
            id: "",
            name: ""
        },
        items: {
            id: {
                label: "节点ID",
                title: "id",
                type: "input",
                disabled: true,
                style: {
                    width: "220px"
                }
            },
            name: {
                label: "节点名称",
                title: "name",
                type: "input",
                placeholder: "请输入节点名称",
                input: val => {
                    this.modeler.updateProperties({
                        name: val
                    })
                },
                style: {
                    width: "220px"
                }
            }
        }
    }
}

// 流程
export function processForm() {
    return {
        models: {
            id: "",
            name: "",
            desc: "",
            var: "",
            type: "",
            formId: "",
        },
        items: {
            id: {
                label: "模型key",
                type: "input",
                style: {
                    width: "220px"
                },
                rules: [{required: true, message: '模型key不能为空', trigger: 'blur'}],
                input: (val) => {
                    this.modeler.updateProperties({
                        id: val,
                        key: val
                    });
                },
            },
            name: {
                label: "模型名称",
                type: "input",
                placeholder: "请输入模型名称",
                rules: [{required: true, message: '模型名称不能为空', trigger: 'blur'}],
                input: (val) => {
                    this.modeler.updateProperties({
                        name: val
                    });
                },
                style: {
                    width: "220px"
                }
            },
            type: {
                label: "模型类型",
                type: "selectTree",
                trigger: "click",
                rules: [{
                    required: true,
                    validator: (rule, value, callback) => {
                        if(this.form.models.type){
                            callback();
                        }else{
                            callback('模型类型不能为空')
                        }
                    }, trigger: 'change'}],
                props: {
                    children: 'children',
                    label: 'name'
                },
                options: [],
                placeholder: "请输入模型类型",
                change: (val) => {
                    this.modeler.updateProperties({
                        type: val
                    });
                },
                style: {
                    width: "220px"
                }
            },
            var: {
                label: "变量",
                type: "select",
                options: [],
                filterable: true,
                allowCreate: true,
                multiple: true,
                defaultFirstOption: true,
                placeholder: "请输入或选择变量",
                style: {
                    width: "220px"
                },
                change: (val) => {
                    this.modeler.updateProperties({
                        var: val.join(",")
                    });
                },
            },
            desc: {
                label: "模型描述",
                type: "textarea",
                row: 4,
                placeholder: "请输入模型描述",
                input: (val) => {
                    this.modeler.updateProperties({
                        desc: val
                    });
                },
                style: {
                    width: "220px"
                }
            },
            formId: {
                label: "表单模板",
                type: "selectTree",
                trigger: "click",
                row: 4,
                placeholder: "请输入模表单模板",
                style: {
                    width: "220px"
                },
                props: {
                    children: 'children',
                    label: 'name'
                },
                options: [],
                change: val => {
                    this.modeler.updateProperties({
                        formId: val || undefined
                    });
                }
            }
        }
    }
}

// 服务任务
export function serviceTaskForm(){
    return {
        models: {
            class: "",
            fields: []
        },
        items: {
            class: {
                label: "执行类",
                type: "select",
                options: [],
                change: (val) => {
                    this.modeler.updateProperties({
                        class: val
                    });
                },
                placeholder: "选择执行类",
                style: {
                    width: "220px"
                }
            },
            fields: {
                label: "选择字段",
                type: "tags",
                style: {
                    width: "220px"
                },
                multiple: true,
                emptyMsg: "未选择字段",
                options: [],
                click: () => {
                    this.fieldsDialogDataReset();
                }
            },
            // desc: {
            //     label: "选择抄送",
            //     type: "tags",
            //     style: {
            //         width: "220px"
            //     },
            //     multiple: true,
            //     emptyMsg: "未选择抄送",
            //     options: [],
            //     click: () => {
            //         this.fieldsDialogDataReset();
            //     }
            // }
        }
    }
}
// 服务任务
export function TaskForm(){
    return {
        models: {
            class: "",
            fields: []
        },
        items: {
            fields: {
                label: "选择抄送",
                type: "tags",
                style: {
                    width: "220px"
                },
                multiple: true,
                emptyMsg: "未选择抄送人",
                options: [],
                click: () => {
                    this.fieldsDialogDataReset();
                }
            }
        }
    }
}

// 用户任务-通用
export function userTaskGeneral() {
    return {
        models: {
            userId: "",
            asynchronous: [],
            monopoly: [],
            authorities: [],
            copies: []
        },
        items: {
            userId: {
                label: "分配用户",
                type: "tags",
                closable: false,
                options: [],
                emptyMsg: "未分配用户",
                click: () => {
                    this.$refs.userTaskDialog.assignVisible = true;
                },
                style: {
                    width: "220px"
                }
            },
            authorities: {
                label: "权限",
                type: "checkbox",
                formItemStyle: {
                    display: "flex"
                },
                formItemClass: "check-box-content",
                options: [],
                change: val => {
                    this.changeAuthority(val)
                }
            },
            copies: {
                label: "抄送人",
                type: "tags",
                closable: false,
                options: [],
                emptyMsg: "未设置抄送人",
                click: this.saveCopiesData,
                style: {
                    width: "220px"
                }
            },
            asynchronous: {
                label: " ",
                type: "checkbox",
                options: [
                    {
                        key: 1,
                        label: "异步"
                    }
                ],
                changeSingle: (val) => {
                    this.form.models.asynchronous = val;
                    this.modeler.updateProperties({
                        async: val
                    });
                }
            },
            monopoly: {
                label: " ",
                type: "checkbox",
                options: [
                    {
                        key: 1,
                        label: "独占",
                        border: true
                    }
                ],
                changeSingle: (val) => {
                    this.form.models.monopoly = val;
                    this.modeler.updateProperties({
                        exclusive: val
                    });
                }
            }
        }
    }
}

// 用户任务-表单
export function userTaskForm() {
    return {
        models: {
            form: [],
        },
        items: {
            form: {
                label: "表单模板",
                type: "select",
                style: {
                    width: "220px"
                },
                placeholder: "请输入模表单模板",
                options: [],
                change: val => {
                    this.modeler.updateProperties({
                        formKey: val || undefined
                    });
                }
            }
        }
    }
}

// 用户任务-监听器
export function userListeners() {
    return {
        models: {
            listeners: [],
        },
        items: {
            listeners: {
                label: "选择监听器",
                type: "tags",
                style: {
                    width: "220px"
                },
                multiple: true,
                emptyMsg: "未选择监听器",
                options: [],
                click: () => {
                    this.listenersDialogDataReset();
                }
            }
        }
    }
}

// 用户任务-多实例表单
export function userMultiInstance() {
    return {
        models: {
            multiInstanceType: "0",
            multiInstanceCardinality: "",
            multiInstanceCollectionVarName: "",
            multiInstanceElementVarName: "",
            multiInstanceCompleteCondition: ""
        },
        items: {
            multiInstanceType: {
                label: "多实例类型",
                type: "select",
                style: {
                    width: "220px"
                },
                options: [
                    {
                        key: "0",
                        label: "不使用多实例",
                        value: "0"
                    },
                    {
                        key: "1",
                        label: "并行",
                        value: "1"
                    },
                    {
                        key: "2",
                        label: "串行",
                        value: "2"
                    }
                ],

                change: this.changeMultiInstanceType
            },
            multiInstanceCardinality: {
                label: "多实例基数",
                style: {
                    width: "220px"
                },
                type: "input",
                input: val => {
                    this.modeler.updateMultiInstanceProps("loopCardinality", val);
                }
            },
            multiInstanceCollectionVarName: {
                label: "多实例集合变量名",
                style: {
                    width: "220px"
                },
                type: "input",
                input: val => {
                    this.modeler.updateBusinessObject(this.modeler.getProperty("loopCharacteristics"), {"collection": val || undefined});
                }
            },
            multiInstanceElementVarName: {
                label: "多实例元素变量名",
                style: {
                    width: "220px"
                },
                type: "input",
                input: val => {
                    this.modeler.updateBusinessObject(this.modeler.getProperty("loopCharacteristics"), {"elementVariable": val || undefined});
                }
            },
            multiInstanceCompleteCondition: {
                label: "多实例完成条件",
                style: {
                    width: "220px"
                },
                type: "input",
                input: val => {
                    this.modeler.updateMultiInstanceProps("completionCondition", val);
                }
            }
        }
    }
}

// 用户任务候选人
export function userTaskAssignForm() {
    return {
        models: {
            assignType: "1",
            complete: [],
            groupList: [],
            checkedUsers: new Set(),
            chooseUserList: []
        },
        items: {
            assignType: {
                label: "分配",
                type: "select",
                options: [
                    {
                        key: "1",
                        label: "分配给流程发起人",
                        value: "1"
                    },
                    {
                        key: "2",
                        label: "分配给单个用户",
                        value: "2"
                    },
                    {
                        key: "3",
                        label: "候选用户",
                        value: "3"
                    },
                    {
                        key: "4",
                        label: "候选组",
                        value: "4"
                    }
                ],
                style: {
                    width: "300px"
                },
                change: val => {this.assignForm.models.assignType = val}
            },
            chooseUserList: {
                type: "component",
                hide: true,
                render: UserTaskAssign,
                props: {
                    rowClick: (row, column, event) => {
                        this.rowClick(row, column, event)
                    }
                }
            },
            checkedUsers: {
                type: "tags",
                hide: true,
                label: "已选择用户",
                closable: true,
                options: [],
                close: (val) => {
                    this.assignForm.models.checkedUsers.delete(val);
                    this.assignForm.items.checkedUsers.options = this.assignForm.items.checkedUsers.options.filter(item => item.label !== val);
                }
            },
            groupList: {
                label: "选择组",
                type: "select",
                multiple: true,
                filterable: true,
                options: [],
                hide: true,
                style: {
                    width: "300px"
                },
            },
            complete: {
                label: " ",
                type: "checkbox",
                options: [
                    {
                        key: 1,
                        label: "允许流程发起人完成任务"
                    }
                ]
            }
        }
    }
}

export function userTaskVarForm(){
    return {
        models: {
            assignType: "1",
            complete: [],
            groupList: [],
            singleUser: "",
            chooseUserList: []
        },
        items: {
            assignType: {
                label: "分配",
                type: "select",
                options: [
                    {
                        key: "1",
                        label: "分配给单个用户",
                        value: "1"
                    },
                    {
                        key: "2",
                        label: "候选用户",
                        value: "2"
                    },
                    {
                        key: "3",
                        label: "候选组",
                        value: "3"
                    }
                ],
                style: {
                    width: "300px"
                },
                change: val => {this.varForm.models.assignType = val}
            },
            singleUser:{
                label: "单个用户变量",
                type: "input",
                hide: false,
                placeholder: "请输入候选用户变量",
                style: {
                    width: "300px"
                },
            },
            chooseUserList: {
                label: "候选用户",
                type: "select",
                hide: true,
                multiple: true,
                filterable: true,
                allowCreate: true,
                defaultFirstOption: true,
                options: [],
                placeholder: "请输入候选用户变量",
                style: {
                    width: "300px"
                },
            },
            groupList: {
                label: "候选组",
                type: "select",
                hide: true,
                multiple: true,
                filterable: true,
                allowCreate: true,
                defaultFirstOption: true,
                placeholder: "请输入候选组变量",
                options: [],
                style: {
                    width: "300px"
                },
            },
            complete: {
                label: " ",
                type: "checkbox",
                options: [
                    {
                        key: 1,
                        label: "允许流程发起人完成任务"
                    }
                ]
            }
        }
    }
}

// 流程连接线
export function sequenceFlowForm() {
    return {
        models: {
            condition: ""
        },
        items: {
            condition: {
                type: "input",
                label: "流条件",
                style: {
                    width: "220px"
                },
                input: val => {
                    this.modeler.updateConditionProps(val)
                }
            }
        }
    }
}

// 子流程
export function subProcessForm() {
    return {
        models: {
            asynchronous: [],
            monopoly: []
        },
        items: {
            asynchronous: {
                label: " ",
                type: "checkbox",
                options: [
                    {
                        key: 1,
                        label: "异步"
                    }
                ],
                changeSingle: (val) => {
                    this.form.models.asynchronous = val;
                    this.modeler.updateProperties({
                        async: val
                    });
                }
            },
            monopoly: {
                label: " ",
                type: "checkbox",
                options: [
                    {
                        key: 1,
                        label: "独占",
                        border: true
                    }
                ],
                changeSingle: (val) => {
                    this.form.models.monopoly = val;
                    this.modeler.updateProperties({
                        exclusive: val
                    });
                }
            },
        }
    }
}

// 网关
export function gatewayForm() {
    return {
        models: {
            asynchronous: [],
            monopoly: []
        },
        items: {
            asynchronous: {
                label: " ",
                type: "checkbox",
                options: [
                    {
                        key: 1,
                        label: "异步"
                    }
                ],
                changeSingle: (val) => {
                    this.form.models.asynchronous = val;
                    this.modeler.updateProperties({
                        async: val
                    });
                }
            },
            monopoly: {
                label: " ",
                type: "checkbox",
                options: [
                    {
                        key: 1,
                        label: "独占",
                        border: true
                    }
                ],
                changeSingle: (val) => {
                    this.form.models.monopoly = val;
                    this.modeler.updateProperties({
                        exclusive: val
                    });
                }
            },
        }
    }
}

// 监听
export function eventForm() {
    return {
        models: {
            listeners: [],
            event: []
        },
        items: {
            listeners: {
                type: "select",
                group: true,
                label: "监听器",
                options: this.listenersListByElement,
                change: this.changeListener
            },
            event: {
                type: "select",
                label: "事件",
                options: [],
                multiple: true,
                change: val => {
                    // console.log(this.eventType);
                    this.currentRow.eventId = Array.isArray(val) ? val : [val];
                }
            }

        }
    }
}

export function fieldForm(){
    return {
        models: {
            fieldName: '',
            fieldType: '',
            fieldValue: '',
        },
        items: {
            fieldName: {
                type: "input",
                label: "字段名称",
                input: val => {
                    this.changeField('fieldName', val)
                }
            },
            fieldType: {
                type: "select",
                options: [],
                label: "字段类型",
                placeholder: "请选择字段类型",
                change: val => {
                    this.changeField("fieldType", val)
                }
            },
            fieldValue: {
                type: "input",
                label: "字段值",
                input: val => {
                    this.changeField('fieldValue', val)
                }
            },
        }
    }
}

export function timerEventForm(){
    return {
        models: {
            type: "",
            content: ""
        },
        items: {
            type: {
                type: "select",
                label: "定时器类型",
                style: {
                    width: "220px"
                },
                options:[
                    {
                        key: "timeDate",
                        label: "日期",
                        value: "timeDate"
                    },
                    {
                        key: "timeDuration",
                        label: "时间段",
                        value: "timeDuration"
                    },
                    {
                        key: "timeCycle",
                        label: "时间循环",
                        value: "timeCycle"
                    }
                ],
                change: val => {
                    this.modeler.updateTimerEventProps({type: val});
                    this.form.models.content = "";
                }
            },
            content: {
                type: "input",
                label: "定义定时器",
                style: {
                    width: "220px"
                },
                input: val => {
                    this.modeler.updateTimerEventProps({val})
                }
            }
        }
    }
}

export function MessageIntermediateCatchEventForm(){
    return {
        models: {
            name: ""
        },
        items: {
            name: {
                type: "input",
                label: "消息名称",
                style: {
                    width: "220px"
                },
                input: val => {
                    this.modeler.updateMessageEventProps({val})
                }
            }
        }
    }
}